import javax.swing.JOptionPane;
import java.util.*;

public class Move extends ActionOrder{

	public Move(Player Owner, Territory Source, Territory Destination, int[] TroopAmount){
        super(Owner, Source, Destination, TroopAmount); 
    }

	protected  boolean checkOwner(){
		if(Source.getOwner() != Owner){
			JOptionPane.showMessageDialog(null, "You can only use your own territory!");
			 return false;
		}
		if (Source.getOwner() == Destination.getOwner()) return true;
        else {
        	JOptionPane.showMessageDialog(null, "You can only move troops between your own territory!");
            return false;
         }
    }

    protected boolean checkPath(Map m){
        if (m.FindPath(Source, Destination)) return true;
        JOptionPane.showMessageDialog(null, "There's no valid path from the source to the destination!");
        return false;
    }     
    
    public void executeOrder(){
    	for (int i = 0; i < 6; i++)
    	   for (int j = 0; j < TroopAmount[i]; j++){
    		   Troop tr = Source.peekTroop(i);
    		   tr.setActioned(true);
    		   Source.removeTroop(i);
    		   Source.addTroop(tr);
    	}
    }
    
    public  String printOrder(){
    	StringBuffer sentence = new StringBuffer();
    	sentence.append("Move");
    	for (int i = 0; i < 6; i++)
    		if (TroopAmount[i] > 0){
    		sentence.append(String.valueOf(TroopAmount[i]));
    		sentence.append(" " + TechnologyName[i] + ", ");
    	}
    	sentence.append(" from " + Source.getLocation() + " to " + Destination.getLocation());
        return sentence.toString();
    }
    	
}
    
    

